package winStrategies;

import gamehandlers.GameHandler;
import java.util.ArrayList;

import sprite.Sprite;


/**
 * This strategy declares a win if Player is the only Sprite left, and declares
 * a loss if Player is destroyed
 * 
 * @author Seon Kang
 * 
 */

public class DefaultWinLossStrategy implements WinLossStrategy {
    private GameHandler myGameHandler;

    /**
     * 
     * @param gamehandler 
     */
    public DefaultWinLossStrategy(GameHandler gamehandler) {
        setMyGameHandler(gamehandler);
    }

    @Override
    public void checkWinLoss() {
        ArrayList<Sprite> spriteList = getMyGameHandler().getMySpriteList();
        Sprite player = myGameHandler.getMyPlayer();
        if (!spriteList.contains(player)) {
            myGameHandler.loseGame();
        }
        else if (spriteList.size() == 1) {
            myGameHandler.winGame();
        }
    }

    /**
     * 
     * @return
     */
    public GameHandler getMyGameHandler() {
        return myGameHandler;
    }

    /**
     * 
     * @param gamehandler 
     */
    public void setMyGameHandler(GameHandler gamehandler) {
        this.myGameHandler = gamehandler;
    }

}
